<?php

/**
 * @author javier steven jimenez
 * 
 * clase que se encargar de la conexion a la BD
 */
class ModeloBase {

    var $server = "localhost";
    var $user = "root";
    var $pass = "";
    var $data_base = "calidad_uso";
    var $conexion;
    var $flag = false;
    var $query = "";
    var $error_conexion = "Error en la conexion a MYSQL";

    function connect() {
        $this->conexion = @mysql_pconnect($this->server, $this->user, $this->pass) or die($this->error_conexion);
        $this->flag = true;
        @mysql_query("SET NAMES utf8");
        return $this->conexion;
    }

    function close() {
        if ($this->flag == true) {
            @mysql_close($this->conexion);
        }
    }

    function query($query) {
        $this->query = @mysql_db_query($this->data_base, $query);
    }

    function f_array() {
        return @mysql_fetch_array($this->query);
    }

    function f_num() {
        return @mysql_num_rows($this->query);
    }

    function select($db) {
        $result = @mysql_select_db($db, $this->conexion);
        if ($result) {
            $this->data_base = $db;
            return true;
        } else {
            return false;
        }
    }
    function f_autoincrent(){
        return mysql_insert_id();
    }

    function free_sql() {
        mysql_free_result($this->query);
    }

    function insertar() {
        foreach ($this->datos as $campo => $valor):
            $campos .= "" . $campo . ", ";
            $valores .= "'" . $valor . "', ";
        endforeach;
        $campos = substr($campos, 0, -2);
        $valores = substr($valores, 0, -2);

        $insert = " INSERT INTO " . $this->tabla;
        $insert .= " ( " . $campos . " )";
        $insert .= " VALUES ( " . $valores . " )";
      
          // echo $insert; 
        $this->query($insert);
        
        return 0;
    }

}

?>
